package com.zhen.aikan.vo;

import com.zhen.aikan.constant.ResultConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author LiJiaZhen
 * @date 2023/9/11 16:20
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "Result对象", description = "返回数据模板")
public class Result {
    @ApiModelProperty("状态码")
    private Integer code;
    @ApiModelProperty("消息")
    private String msg;
    @ApiModelProperty("数据")
    private Object data;

    public static Result ok() {
        return new Result(ResultConstant.ResultEnum.SUCCESS.getCode(), null, null);
    }

    public static Result ok(Object data) {
        return new Result(ResultConstant.ResultEnum.SUCCESS.getCode(),
                ResultConstant.ResultEnum.SUCCESS.getMsg(), data);
    }

    public static Result fail() {
        return new Result(ResultConstant.ResultEnum.ERROR.getCode(),
                ResultConstant.ResultEnum.ERROR.getMsg(), null);
    }

    public static Result fail(String msg) {
        return new Result(ResultConstant.ResultEnum.ERROR.getCode(),
                msg, null);
    }
}
